//
// Created by 12992 on 24-10-20.
//

#include "IconButton.h"
#include <QHBoxLayout>
#include <QLabel>


namespace gui::widgets
{
    IconButton::IconButton(const QImage& image, const QString& text, QWidget* parent)
            : QPushButton(parent)
    {
        auto layout = new QHBoxLayout(this);
        layout->setSpacing(0);
        auto imageLabel = new QLabel(this);
        imageLabel->setPixmap(QPixmap::fromImage(image).scaled(22, 22, Qt::KeepAspectRatio,
                                                               Qt::TransformationMode::SmoothTransformation));
        auto textLabel = new QLabel(this);
        textLabel->setText(text);
        layout->addWidget(imageLabel);
        layout->addWidget(textLabel);
        this->setLayout(layout);
        QString style = R"(
QPushButton {
border: none;
background-color: transparent;
height: 50px;
width: 100px;
border-radius: 3px;
}

QPushButton:hover {
background-color: rgba(128, 128, 128, 0.5);
}
QPushButton:pressed {
background-color: rgba(64, 64, 64, 0.5);
}
)";
        this->setStyleSheet(style);
    }
}